﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;

namespace _2301MVCDemo.Controllers
{
    public class LoginController : Controller
    {
        // GET: Login
        public ActionResult Index()
        {
            //当View()无参数时，返回方法名同名的视图，即Index.cshtml
            //当View("参数")有参数时，返回参数名同名的视图，即参数.cshtml
            return View();
            //return View("Page1");
        }

        public ActionResult Page1()
        {
            //当View()无参数时，返回方法名同名的视图，即Index.cshtml
            //当View("参数")有参数时，返回参数名同名的视图，即参数.cshtml
            return View();
            //return View("Page1");
        }

        public ActionResult DoLogin(string name)
        {
            if (name == "admin")
            {
                //授权
                FormsAuthentication.SetAuthCookie(name,false);
                return RedirectToAction("Index","Home");
            }
            else
            {
                ViewBag.tip = "账号错误！";
                return View("Index");
            }
        }
    }
}